package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.RewardDao;
import com.qfedu.stussm.dao.TuitionDao;
import com.qfedu.stussm.entity.Reward;
import com.qfedu.stussm.entity.Tuition;
import com.qfedu.stussm.service.intf.RewardService;
import com.qfedu.stussm.service.intf.TuitionService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TuitionServiceImpl implements TuitionService {
    @Autowired
    private TuitionDao tuitionDao;

    @Override
    public R add(Tuition tuition) {
        if (tuitionDao.add(tuition) >0) {
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBeanVo selectAll(String keyword, int page, int limit) {
        if(keyword != null && keyword.length() > 0){
            keyword="%"+keyword+"%";
        }else{
            keyword = null;
        }
        PageHelper.startPage(page, limit);
        PageInfo<Tuition> pageInfo = new PageInfo<>(tuitionDao.queryAll(keyword));
        return new PageBeanVo(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public R update(Tuition tuition) {
        if (tuitionDao.update(tuition) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @Override
    public R delbyids(List<Integer> ids) {
        if (tuitionDao.delbyids(ids)>0){
            return R.ok();
        } else {
            return R.fail();
        }
    }
}
